﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using SAKS.Models;
using NUnit.Framework;
namespace SAKS.UnitTest
{
    /// <summary>
    /// 为SAKS网站初始化数据库，不是为了单元测试
    /// </summary>
    [TestFixture]
    public class PoputateDatabase : TestBase
    {
        [Test]
        public void PopulateDatabase()
        {

        }
        protected override void CreateSomeData(NHibernate.ISession session)
        {
            var role_admin = new Role
            {
                RoleName = "Admin",
                Description = "系统管理员",
                Users = new List<User>()
            };
            var role_superviser = new Role
            {
                RoleName = "Superviser",
                Description = "科研管理员",
                Users = new List<User>()
            };
            var role_1 = new Role
            {
                RoleName = "Editor",
                Description = "信息维护员",
                Users = new List<User>()
            };
            var membership = new Membership
            {
                Password = "123456",
                PasswordFormat = PasswordFormat.Clear,
                PasswordSalt = "",
                CreateDate = DateTime.Now,
                Email = "admin@126.com",
                LoweredEmail = "admin@126.com",
                LastLoginDate = DateTime.Now,
                LastPasswordChangedDate = DateTime.Now,
            };
            var user = new User
            {
                UserName = "admin",
                LoweredUserName = "admin",
                IsAnonymous = false,
                LastActivityDate = DateTime.Now,
                Roles = new List<Role>() { role_admin },
                Membership = membership
            };

            role_admin.Users.Add(user);
            membership.User = user;
            session.Save(role_admin);

            session.Save(role_superviser);
            session.Save(user);
            session.Save(role_1);
            var Message = new MessageReceived
            {
                FromName = "admin",
                ToName = "admin",
                Subject = "Test",
                HasRead = false,
                Date = DateTime.Now,
                Type = MessageType.User
            };
            session.Save(Message);

            
            for (int i = 0; i < 100; i++)
            {
                var project = new Project
                {
                    Administrator = user,
                    PrimaryDesigner = "test",
                    CreatedDate = DateTime.Now,
                    SerialNumber = 123,
                    SpecializedField = "test",
                    State = ProjectState.Created,
                    StartDate = DateTime.Now.AddDays(-1),
                    EndDate = DateTime.Now,
                    Name = "test",
                    Users = new List<User>() { user },
                    ResponsibleOfficer = "test",
                    ProjectLevel = "2",
                    Members = new List<string>() { "test1", "test2" }
                };
                user.AddProject(project);
                session.Save(project);
            }
            for (int i = 0; i < 20; i++)
            {
                var achi = new Achievement
                {
                    Name = "test",
                    PrimaryCompleteOrganization = "test",
                    PrimaryCompletePerson = "test",
                    CreatedDate = DateTime.Now
                };
                var eva = new AchiEvaluation
                {
                    EvaluateMethod = "test"
                };
                achi.Evaluation = eva;
                eva.Achievement = achi;
                session.Save(achi);
            }
            session.Update(user);
        }


    }
}
